package front

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"supervideo/app/models/video"
	"supervideo/app/models/zone"
	"supervideo/pkg/database"
)

type IndexController struct {
}

func (index IndexController) Index(c *gin.Context) {

	// 搜索区间
	zones := &[]zone.Zone{}
	database.DB.Order("sort desc").Find(&zones)

	// 电影推荐
	recommendMovies := &[]video.Video{}
	database.DB.Order("rand()").Where("zone_id = ? and status = ?", 1, 1).Limit(10).Find(&recommendMovies)

	// 剧集推荐
	recommendDramas := &[]video.Video{}
	database.DB.Order("rand()").Where("zone_id = ? and status = ?", 2, 1).Limit(10).Find(&recommendDramas)

	// 综艺推荐
	recommendVarietyShows := &[]video.Video{}
	database.DB.Order("rand()").Where("zone_id = ? and status = ?", 3, 1).Limit(10).Find(&recommendVarietyShows)

	// 动漫推荐
	recommendAnimations := &[]video.Video{}
	database.DB.Order("rand()").Where("zone_id = ? and status = ?", 4, 1).Limit(10).Find(&recommendAnimations)

	c.HTML(http.StatusOK, "index.html", gin.H{
		"title":                 "Home",
		"zones":                 zones,
		"zone_id":               0,
		"recommendMovies":       recommendMovies,
		"recommendDramas":       recommendDramas,
		"recommendVarietyShows": recommendVarietyShows,
		"recommendAnimations":   recommendAnimations,
	})
}
